package com.zw.yzk.kabu.mapper;

import com.zw.yzk.kabu.data.network.entity.HomePageEntity;
import com.zw.yzk.kabu.model.CosplayModel;
import com.zw.yzk.kabu.model.HomepageHeaderModel;
import com.zw.yzk.kabu.utils.TimeFormatUtils;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

/**
 * Created by zhanwei on 2017/3/4.
 */

public class HomePagerMapper {

    @Inject
    public HomePagerMapper() {

    }

    public HomepageHeaderModel transferHeader(HomePageEntity entity) {
        HomepageHeaderModel model = new HomepageHeaderModel();
        model.setBackgroundUrl(entity.result.details.homePage);
        model.setNickName(entity.result.details.nickName);
        model.setRemark(entity.result.details.introduction);
        model.setHeadUrl(entity.result.details.head);
        model.setStar(entity.result.details.isFame == 1);
        model.setConcernCount(entity.result.details.totalFollow);
        model.setFansCount(entity.result.details.totalFans);
        model.setRank(entity.result.details.rankingId);
        model.setAlbumCount(entity.result.albumCount);
        model.setFollowState(entity.result.followState);
        model.setUserId(entity.result.details.userId);

        return model;
    }

    public CosplayModel transferCos(HomePageEntity.Cosplay item) {
        CosplayModel model = new CosplayModel();
        model.setId(item.id);
        model.setPublisher(item.publisher);
        model.setPublisherHeadUrl(item.publishHeadUrl);
        try {
            model.setPublishTime(TimeFormatUtils.getTimeInterval(item.publishTime, "yyyy-MM-dd HH:mm:ss"));
        } catch (Exception e) {
            model.setPublishTime(item.publishTime);
        }
        model.setPublishAddress(item.publishAddress);
        model.setMessage(item.message);
        model.setCosUrl(item.imageUrl);
        model.setPraiseCount(item.praiseCount);
        model.setPraise(item.isPraised);
        model.setCollected(item.collect);
        model.setCommentCount(item.commentCount);
        model.setCompetition(item.isCompetition == 1);

        return model;
    }

    public List<CosplayModel> transferCosList(HomePageEntity entity) {
        List<CosplayModel> modelList = new ArrayList<>();
        if (entity.result.cosplayList == null || entity.result.cosplayList.isEmpty()) {
            return modelList;
        }
        for (HomePageEntity.Cosplay item : entity.result.cosplayList) {
            modelList.add(transferCos(item));
        }
        return modelList;
    }
}
